<?php

function getOrderNo($userId = 0){
    if($userId){
        $userId = str_pad($userId,5,"02",STR_PAD_LEFT);
    }
    $sn = date('Ymd').substr(implode(NULL, array_map('ord', str_split(substr(uniqid(), 7, 13), 1))), 0, 8);
    if($userId){
        $sn .= $userId;
    }
    
    return $sn;
}